package web.servlet.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

/**
 * @Author Administrator
 * @Date 2020/5/15 8:30
 **/
@WebServlet("/requestDemo3")
public class RequestDemo3 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       /*BufferedReader br = req.getReader();
        String line=null;
        while ((line=br.readLine())!=null){
            System.out.println(line);
        }*/
       /* if(br!=null){
            br.close();
        }
       */
       String username = req.getParameter("username");
        Map<String, String[]> parameterMap = req.getParameterMap();
        String[] hobbies = req.getParameterValues("hobby");
        System.out.println("username:"+username);
        for (int i = 0; i < hobbies.length; i++) {
            System.out.println("hobbies:"+hobbies[i]);
        }
        System.out.println("所有的请求参数");
        Iterator<String> iterator = parameterMap.keySet().iterator();
        while (iterator.hasNext()){
            String key = iterator.next();
            String[] value = parameterMap.get(key);
            System.out.println(key+":");
            for (String s:
                 value) {
                System.out.println(s);
            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
